package com.shop.loan.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shop.loan.mapper.LoanOrderByMybatisMapper;
import com.shop.loan.model.entity.LoanOrderByMybatis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.OperationHandler;
import xyz.erupt.upms.service.EruptUserService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 逾期池领取操作
 */
@Slf4j
@Service
public class LoanOrderPoolByCollectionGetHandler implements OperationHandler<Object, Void> {

    @Resource
    LoanOrderByMybatisMapper loanOrderByMybatisMapper;

    @Resource
    EruptUserService eruptUserService;

    @Override
    public String exec(List<Object> data, Void unused, String[] param) {
        for (Object item : data) {
            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(item));

            LoanOrderByMybatis loanOrderByMybatis = new LoanOrderByMybatis();
            loanOrderByMybatis.setId(jsonObject.getLongValue("id"));
            loanOrderByMybatis.setCollectionServiceId(eruptUserService.getCurrentUid());
            loanOrderByMybatisMapper.updateByPrimaryKeySelective(loanOrderByMybatis);
        }
        return null;
    }
}
